<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/google/protobuf/stubs/once.h</title>
  <link rel="stylesheet" type="text/css" href="../../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../../index.html">top level</a> - <a href="index.html">usr/include/google/protobuf/stubs</a> - once.h<span style="font-size: 80%;"> (source / <a href="once.h.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">5</td>
            <td class="headerCovTableEntry">5</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">1</td>
            <td class="headerCovTableEntry">1</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : // Protocol Buffers - Google's data interchange format</a>
<span class="lineNum">       2 </span>            : // Copyright 2008 Google Inc.  All rights reserved.
<span class="lineNum">       3 </span>            : // https://developers.google.com/protocol-buffers/
<span class="lineNum">       4 </span>            : //
<span class="lineNum">       5 </span>            : // Redistribution and use in source and binary forms, with or without
<span class="lineNum">       6 </span>            : // modification, are permitted provided that the following conditions are
<span class="lineNum">       7 </span>            : // met:
<span class="lineNum">       8 </span>            : //
<span class="lineNum">       9 </span>            : //     * Redistributions of source code must retain the above copyright
<span class="lineNum">      10 </span>            : // notice, this list of conditions and the following disclaimer.
<span class="lineNum">      11 </span>            : //     * Redistributions in binary form must reproduce the above
<span class="lineNum">      12 </span>            : // copyright notice, this list of conditions and the following disclaimer
<span class="lineNum">      13 </span>            : // in the documentation and/or other materials provided with the
<span class="lineNum">      14 </span>            : // distribution.
<span class="lineNum">      15 </span>            : //     * Neither the name of Google Inc. nor the names of its
<span class="lineNum">      16 </span>            : // contributors may be used to endorse or promote products derived from
<span class="lineNum">      17 </span>            : // this software without specific prior written permission.
<span class="lineNum">      18 </span>            : //
<span class="lineNum">      19 </span>            : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
<span class="lineNum">      20 </span>            : // &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
<span class="lineNum">      21 </span>            : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
<span class="lineNum">      22 </span>            : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
<span class="lineNum">      23 </span>            : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
<span class="lineNum">      24 </span>            : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
<span class="lineNum">      25 </span>            : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
<span class="lineNum">      26 </span>            : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
<span class="lineNum">      27 </span>            : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<span class="lineNum">      28 </span>            : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<span class="lineNum">      29 </span>            : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            : // Author: kenton@google.com (Kenton Varda)
<span class="lineNum">      32 </span>            : //
<span class="lineNum">      33 </span>            : // emulates google3/base/once.h
<span class="lineNum">      34 </span>            : //
<span class="lineNum">      35 </span>            : // This header is intended to be included only by internal .cc files and
<span class="lineNum">      36 </span>            : // generated .pb.cc files.  Users should not use this directly.
<span class="lineNum">      37 </span>            : //
<span class="lineNum">      38 </span>            : // This is basically a portable version of pthread_once().
<span class="lineNum">      39 </span>            : //
<span class="lineNum">      40 </span>            : // This header declares:
<span class="lineNum">      41 </span>            : // * A type called ProtobufOnceType.
<span class="lineNum">      42 </span>            : // * A macro GOOGLE_PROTOBUF_DECLARE_ONCE() which declares a variable of type
<span class="lineNum">      43 </span>            : //   ProtobufOnceType.  This is the only legal way to declare such a variable.
<span class="lineNum">      44 </span>            : //   The macro may only be used at the global scope (you cannot create local or
<span class="lineNum">      45 </span>            : //   class member variables of this type).
<span class="lineNum">      46 </span>            : // * A function GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()).
<span class="lineNum">      47 </span>            : //   This function, when invoked multiple times given the same ProtobufOnceType
<span class="lineNum">      48 </span>            : //   object, will invoke init_func on the first call only, and will make sure
<span class="lineNum">      49 </span>            : //   none of the calls return before that first call to init_func has finished.
<span class="lineNum">      50 </span>            : // * The user can provide a parameter which GoogleOnceInit() forwards to the
<span class="lineNum">      51 </span>            : //   user-provided function when it is called. Usage example:
<span class="lineNum">      52 </span>            : //     int a = 10;
<span class="lineNum">      53 </span>            : //     GoogleOnceInit(&amp;my_once, &amp;MyFunctionExpectingIntArgument, &amp;a);
<span class="lineNum">      54 </span>            : // * This implementation guarantees that ProtobufOnceType is a POD (i.e. no
<span class="lineNum">      55 </span>            : //   static initializer generated).
<span class="lineNum">      56 </span>            : //
<span class="lineNum">      57 </span>            : // This implements a way to perform lazy initialization.  It's more efficient
<span class="lineNum">      58 </span>            : // than using mutexes as no lock is needed if initialization has already
<span class="lineNum">      59 </span>            : // happened.
<span class="lineNum">      60 </span>            : //
<span class="lineNum">      61 </span>            : // Example usage:
<span class="lineNum">      62 </span>            : //   void Init();
<span class="lineNum">      63 </span>            : //   GOOGLE_PROTOBUF_DECLARE_ONCE(once_init);
<span class="lineNum">      64 </span>            : //
<span class="lineNum">      65 </span>            : //   // Calls Init() exactly once.
<span class="lineNum">      66 </span>            : //   void InitOnce() {
<span class="lineNum">      67 </span>            : //     GoogleOnceInit(&amp;once_init, &amp;Init);
<span class="lineNum">      68 </span>            : //   }
<span class="lineNum">      69 </span>            : //
<span class="lineNum">      70 </span>            : // Note that if GoogleOnceInit() is called before main() has begun, it must
<span class="lineNum">      71 </span>            : // only be called by the thread that will eventually call main() -- that is,
<span class="lineNum">      72 </span>            : // the thread that performs dynamic initialization.  In general this is a safe
<span class="lineNum">      73 </span>            : // assumption since people don't usually construct threads before main() starts,
<span class="lineNum">      74 </span>            : // but it is technically not guaranteed.  Unfortunately, Win32 provides no way
<span class="lineNum">      75 </span>            : // whatsoever to statically-initialize its synchronization primitives, so our
<span class="lineNum">      76 </span>            : // only choice is to assume that dynamic initialization is single-threaded.
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span>            : #ifndef GOOGLE_PROTOBUF_STUBS_ONCE_H__
<span class="lineNum">      79 </span>            : #define GOOGLE_PROTOBUF_STUBS_ONCE_H__
<span class="lineNum">      80 </span>            : 
<span class="lineNum">      81 </span>            : #include &lt;google/protobuf/stubs/atomicops.h&gt;
<span class="lineNum">      82 </span>            : #include &lt;google/protobuf/stubs/common.h&gt;
<span class="lineNum">      83 </span>            : 
<span class="lineNum">      84 </span>            : namespace google {
<span class="lineNum">      85 </span>            : namespace protobuf {
<span class="lineNum">      86 </span>            : 
<span class="lineNum">      87 </span>            : #ifdef GOOGLE_PROTOBUF_NO_THREAD_SAFETY
<span class="lineNum">      88 </span>            : 
<span class="lineNum">      89 </span>            : typedef bool ProtobufOnceType;
<span class="lineNum">      90 </span>            : 
<span class="lineNum">      91 </span>            : #define GOOGLE_PROTOBUF_ONCE_INIT false
<span class="lineNum">      92 </span>            : 
<span class="lineNum">      93 </span>            : inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) {
<span class="lineNum">      94 </span>            :   if (!*once) {
<span class="lineNum">      95 </span>            :     *once = true;
<span class="lineNum">      96 </span>            :     init_func();
<span class="lineNum">      97 </span>            :   }
<span class="lineNum">      98 </span>            : }
<span class="lineNum">      99 </span>            : 
<span class="lineNum">     100 </span>            : template &lt;typename Arg&gt;
<span class="lineNum">     101 </span>            : inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)(Arg),
<span class="lineNum">     102 </span>            :     Arg arg) {
<span class="lineNum">     103 </span>            :   if (!*once) {
<span class="lineNum">     104 </span>            :     *once = true;
<span class="lineNum">     105 </span>            :     init_func(arg);
<span class="lineNum">     106 </span>            :   }
<span class="lineNum">     107 </span>            : }
<span class="lineNum">     108 </span>            : 
<span class="lineNum">     109 </span>            : #else
<span class="lineNum">     110 </span>            : 
<span class="lineNum">     111 </span>            : enum {
<span class="lineNum">     112 </span>            :   ONCE_STATE_UNINITIALIZED = 0,
<span class="lineNum">     113 </span>            :   ONCE_STATE_EXECUTING_CLOSURE = 1,
<span class="lineNum">     114 </span>            :   ONCE_STATE_DONE = 2
<span class="lineNum">     115 </span>            : };
<span class="lineNum">     116 </span>            : 
<span class="lineNum">     117 </span>            : typedef internal::AtomicWord ProtobufOnceType;
<span class="lineNum">     118 </span>            : 
<span class="lineNum">     119 </span>            : #define GOOGLE_PROTOBUF_ONCE_INIT ::google::protobuf::ONCE_STATE_UNINITIALIZED
<span class="lineNum">     120 </span>            : 
<span class="lineNum">     121 </span>            : LIBPROTOBUF_EXPORT
<a name="122"><span class="lineNum">     122 </span>            : void GoogleOnceInitImpl(ProtobufOnceType* once, Closure* closure);</a>
<span class="lineNum">     123 </span>            : 
<span class="lineNum">     124 </span><span class="lineCov">        699 : inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) {</span>
<span class="lineNum">     125 </span><span class="lineCov">        699 :   if (internal::Acquire_Load(once) != ONCE_STATE_DONE) {</span>
<span class="lineNum">     126 </span><span class="lineCov">          1 :     internal::FunctionClosure0 func(init_func, false);</span>
<span class="lineNum">     127 </span><span class="lineCov">          1 :     GoogleOnceInitImpl(once, &amp;func);</span>
<span class="lineNum">     128 </span>            :   }
<span class="lineNum">     129 </span><span class="lineCov">        699 : }</span>
<span class="lineNum">     130 </span>            : 
<span class="lineNum">     131 </span>            : template &lt;typename Arg&gt;
<span class="lineNum">     132 </span>            : inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)(Arg*),
<span class="lineNum">     133 </span>            :     Arg* arg) {
<span class="lineNum">     134 </span>            :   if (internal::Acquire_Load(once) != ONCE_STATE_DONE) {
<span class="lineNum">     135 </span>            :     internal::FunctionClosure1&lt;Arg*&gt; func(init_func, false, arg);
<span class="lineNum">     136 </span>            :     GoogleOnceInitImpl(once, &amp;func);
<span class="lineNum">     137 </span>            :   }
<span class="lineNum">     138 </span>            : }
<span class="lineNum">     139 </span>            : 
<span class="lineNum">     140 </span>            : #endif  // GOOGLE_PROTOBUF_NO_THREAD_SAFETY
<span class="lineNum">     141 </span>            : 
<span class="lineNum">     142 </span>            : class GoogleOnceDynamic {
<span class="lineNum">     143 </span>            :  public:
<span class="lineNum">     144 </span>            :   GoogleOnceDynamic() : state_(GOOGLE_PROTOBUF_ONCE_INIT) { }
<span class="lineNum">     145 </span>            : 
<span class="lineNum">     146 </span>            :   // If this-&gt;Init() has not been called before by any thread,
<span class="lineNum">     147 </span>            :   // execute (*func_with_arg)(arg) then return.
<span class="lineNum">     148 </span>            :   // Otherwise, wait until that prior invocation has finished
<span class="lineNum">     149 </span>            :   // executing its function, then return.
<span class="lineNum">     150 </span>            :   template&lt;typename T&gt;
<span class="lineNum">     151 </span>            :   void Init(void (*func_with_arg)(T*), T* arg) {
<span class="lineNum">     152 </span>            :     GoogleOnceInit&lt;T&gt;(&amp;this-&gt;state_,
<span class="lineNum">     153 </span>            :                       func_with_arg,
<span class="lineNum">     154 </span>            :                       arg);
<span class="lineNum">     155 </span>            :   }
<span class="lineNum">     156 </span>            :  private:
<span class="lineNum">     157 </span>            :   ProtobufOnceType state_;
<span class="lineNum">     158 </span>            : };
<span class="lineNum">     159 </span>            : 
<span class="lineNum">     160 </span>            : #define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \
<span class="lineNum">     161 </span>            :   ::google::protobuf::ProtobufOnceType NAME = GOOGLE_PROTOBUF_ONCE_INIT
<span class="lineNum">     162 </span>            : 
<span class="lineNum">     163 </span>            : }  // namespace protobuf
<span class="lineNum">     164 </span>            : }  // namespace google
<span class="lineNum">     165 </span>            : 
<span class="lineNum">     166 </span>            : #endif  // GOOGLE_PROTOBUF_STUBS_ONCE_H__
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
